<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');	 
class Verifylogin_sensei extends CI_Controller {
    function __construct()
    {
        parent::__construct();
	$this->load->model('Login_m');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->model('Readcsvlogin_m');
        $this->load->model('Comment_m');
    } 
    function index()
    {
        
        if($this->check_sensei()==0)
        {
            $data['error_login']="ユーザーまたはパースワードが違い!";
            $data['query']=$this->Login_m->select_mg();
            $this->load->view('login/login_sensei_v',$data);
        }   
        else if($this->check_sensei()==2)
        {
            $session_data_mk = $this->session->userdata('logged_in_mk');
            $id_mk = $session_data_mk['id_mk'];
            $manager_mk=$session_data_mk['manager_mk'];
            $this->Login_m->update_online_mk1($id_mk,$manager_mk,1);
            redirect('maker', 'refresh');
        }
    }
    function check_sensei()
    {
        $id = $this->input->post('txtID');
        $password = $this->input->post('txtPass');
        $manager = $this->input->post('txtManager');
        //$result_ex = $this->Login_m->login_examiner1($id, $password,$manager);
        $result_mk = $this->Login_m->login_maker1($id, $password,$manager);
        if($this->Login_m->select_online_flag_mk1($id,$manager)->num_rows()>0)
                return 0;
        if($result_mk)
        {
            $sess_array_maker = array();
            foreach($result_mk as $row_mk)
            {
                $sess_array_maker = array('id_mk' => $row_mk->id_mk,'manager_mk'=>$row_mk->id_mg);
                $this->session->set_userdata('logged_in_mk', $sess_array_maker);
            }
            return 2;
        }
        else
            return 0;
    }
}